home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 October / enter-2005-10.iso / files / jedit42install.exe / {app} / macros / Editing / Move_Line_Down.bsh < prev    next >
Encoding:
Text File  |  2004-08-29  |  2.4 KB  |  74 lines

  1. /*
  2.  * Move_Line_Down.bsh - a BeanShell macro for moving lines down.
  3.  *
  4.  * Copyright (C) 2004 Nicholas O'Leary nol@deferential.net
  5.  * 
  6.  * :mode=beanshell:tabSize=3:indentSize=3:maxLineLen=0:noTabs=true:
  7.  * :indentOnTab=true:indentOnEnter=true:folding=explicit:collapseFolds=1:
  8.  *
  9.  * {{{ License
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License
  12.  * as published by the Free Software Foundation; either version 2
  13.  * of the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with the jEdit program; if not, write to the Free Software
  22.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  23.  * }}}
  24.  *
  25.  *  
  26.  * Changes:
  27.  *  05-Jul-04: Initial Implementation
  28.  *
  29.  * $Id: Move_Line_Down.bsh,v 1.1 2004/07/06 00:14:58 spestov Exp $
  30.  */
  31.  
  32. // Get the current line 
  33. int lineNo = textArea.getCaretLine();
  34.  
  35. // Make sure we are allowed to edit the buffer, and that we're not at the bottom
  36. if (!buffer.isEditable() || lineNo == buffer.getLineCount()-1) {
  37.    textArea.getToolkit().beep();
  38.    return 1;
  39. }
  40. // Start the edit
  41. buffer.beginCompoundEdit();
  42. // Get the caret position on the line
  43. int lineCaretOffset = textArea.getCaretPosition()-buffer.getLineStartOffset(lineNo);
  44. // Get the line text to move
  45. String line = buffer.getLineText(lineNo);
  46. // Remove the line
  47. textArea.deleteLine();
  48. // Get the position to insert the line at
  49. int newLinePos = buffer.getLineEndOffset(lineNo);
  50. // If this is the penultimate line, do a slightly different insert
  51. if (newLinePos > buffer.getLength()) { 
  52.    buffer.insert(buffer.getLength(),"\n"+line);
  53. } else {
  54.    buffer.insert(newLinePos,line+"\n");
  55. }   
  56. // Move the cursor into the same position on the new line
  57. textArea.setCaretPosition(newLinePos+lineCaretOffset);
  58. // Indent this line
  59. buffer.indentLine(lineNo+1,true);
  60. // End the edit
  61. buffer.endCompoundEdit();
  62.  
  63. /*
  64.  
  65. Macro index data (in DocBook format)
  66.  
  67.    <listitem>
  68.       <para><filename>Move_Line_Down.bsh</filename></para>
  69.       <abstract><para>Moves the current line down one, with automatic 
  70.       indentation.</para></abstract>   
  71.       </listitem>
  72.  
  73. */
  74.